<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>用户登录</title>
        <link href="../css/user-login.css" type="text/css" rel="stylesheet"/>
    </head>
<body>
<div class="login-back">
    <div class="table">
        <div class="table-cell">
            <div class="login-logo">
                <img src="../images/login-logo.png" alt="">
            </div>
            <div class="login-title">数联医信 - 运营平台</div>
        </div>
    </div>
</div>
<div class="login-box">
    <div class="user-input margin-top clear">
        <i class="left i-n"></i>
        <input class="left" placeholder="用户名" id="userName"/>
    </div>
    <div class="user-input clear password-input">
        <i class="left i-p"></i>
        <input class="left" placeholder="密码" type="password" id="password" onkeydown="EnterPress()"/>
        <p class="error-msg" style="display: none"></p>
    </div>
    <a class="login-btn" href="javascript:;" onclick="Login_1()">登录</a>
    <a class="login-btn toKeyData" href="javascript:;"  onclick="Login_2()" style="visibility: hidden">登录</a>
    <a class="login-btn toTrendData" href="javascript:;"  onclick="Login_3()" style="visibility: hidden">登录</a>
    <div class="forget clear">
        <!--<label class="left"><input type="checkbox"/>记住密码</label>-->
        <!--<a class="right" href="#">忘记密码？</a>-->
    </div>
    <div class="bottom-info">Copyright  2016 Bigdata Boost Service LTD. All Rights Reserved. 蜀ICP备15000139号</div>
</div>
<script src="../js/jquery.min.js"></script>
<script src="../js/jquery.cookie.js"></script>

<script src="../js/user-tree.js"></script>

<script type="text/javascript">

    var _ip = location.origin;
    if(_ip.indexOf('localhost') != -1){
          _ip = 'http://121.42.187.170'; //本地
        // _ip = 'http://192.168.8.31:8080'  //展播
        // _ip = 'http://10.0.2.14:8080/operation-web'; //广播
//        _ip = 'http://10.0.1.81:8888';
//       _ip = 'http://121.42.252.26';
    }else{
        //will remove after project complete
         _ip = 'http://121.42.252.26';
    }
    function Login(firstUrl) {
        $('.error-msg').remove();
//        $('.user-input').removeClass('error').removeClass('focus');
        var url = _ip + '/login';
        var data = {
            userName: $('#userName').val(),
            password: $('#password').val()
        };

        if(!data.userName) {
            $('#userName').closest('.user-input').addClass('error').after('<p class="error-msg">请输入用户名</p>');
            return false;
        }
        if(!data.password) {
            $('#password').closest('.user-input').addClass('error').after('<p class="error-msg">请输入密码</p>');
            return false;
        }
        organizeAjaxPost(url, data, function(json) {
            if (json.success) {
                $.cookie('userid',json.data.id);
                $.cookie('userrole',json.data.role);
                sessionStorage.removeItem("bug");
                sessionStorage.removeItem("allPro");
                sessionStorage.removeItem("memsNeed");
                sessionStorage.removeItem("pmNeed");
                window.location.href = firstUrl || 'mems-pro-list.html';
            }
            else {
                $('#userName').closest('.user-input').addClass('error').after('<p class="error-msg">'+ json.message +'</p>');
            }
        });
    }
    function Login_1(){
        var url = 'mems-pro-list.html'
        Login(url)
    }
    function Login_2(){
        var url = 'key-data.html?beginDate='+$$.getUrlParaObj().beginDate+'&endDate='+$$.getUrlParaObj().endDate
        Login(url)
    }
    function Login_3(){
        var url = 'trend-count.html?dateRange='+$$.getUrlParaObj().dateRange+'&endDate='+$$.getUrlParaObj().endDate
        Login(url)
    }
     function EnterPress(e){ //传入 event
         var e = e || window.event;
         if(e.keyCode == 13){
             Login()
         }
     }
    $('.user-input').on('focus', 'input', function() {
        var $obj = $(this);
        $obj.closest('.user-input').addClass('focus');
        $('.error-msg').css({'display':'none'});
    }).on('blur', 'input', function() {
        var $obj = $(this);
        $obj.closest('.user-input').removeClass('focus');
        $('.error-msg').css({'display':'none'});
    })


    var $$ = {}
    $$.getUrlParaObj = function(k){
        var search = location.search;
        if(search != "" && search.length >= 1){
            var search = search.split('?')[1];

            var param  = {};
            var arr = search.split('&');
            for(var k = 0, kk = arr.length; k < kk ; k++){
                var d = arr[k].split('=');
                param[d[0]] = decodeURI(d[1])
            }
        }
        return param;
    }
</script>
</body>
</html>